package com.hotacorp.opencloud.authserver.exception;

import com.fasterxml.jackson.core.JsonGenerator;
import com.fasterxml.jackson.databind.SerializerProvider;
import com.fasterxml.jackson.databind.ser.std.StdSerializer;
import com.hotacorp.opencloud.common.commdata.Result;

import lombok.SneakyThrows;

/**
 * 定制序列化因为CustomAuth2Exception的输出
 * @author lwg
 *
 */
public class CustomAuth2ExceptionSerializer extends StdSerializer<CustomAuth2Exception> {
	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;

	public CustomAuth2ExceptionSerializer() {
		super(CustomAuth2Exception.class);
	}

	@Override
	@SneakyThrows
	public void serialize(CustomAuth2Exception value, JsonGenerator gen, SerializerProvider provider) {
		Result<String> retResult = new Result<>("", value.getErrorCode(), value.getLocalizedMessage());
		gen.writeObject(retResult);
	}
}